home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-1.iso / Files / Educ / Calc / MathPad 2.35.sit / Examples / root finder < prev    next >
MacBinary  |  1994-06-14  |  1.8 KB  |  [TEXT/MPad]

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: MacBinary (archive/macBinary).

You can browse this item here: root finder

ConfidenceProgramDetectionMatch TypeSupport
10% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, inited, Tue Jun 14 15:47:21 1994, modified Tue Jun 14 15:47:21 1994, creator 'MPad', type ASCII, 1220 bytes "root finder" , at 0x544 342 bytes resource default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[MPad]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 0b 72 6f 6f 74 20 66 | 69 6e 64 65 72 00 00 00 |..root f|inder...|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 4d 50 61 | 64 01 00 00 00 00 00 00 |.TEXTMPa|d.......|
|00000050| 00 00 00 00 00 04 c4 00 | 00 01 56 aa 23 b9 c9 aa |........|..V.#...|
|00000060| 23 b9 c9 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |#.......|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 a6 d4 00 00 |........|........|
|00000080| 2d 2d 20 46 69 6e 64 20 | 61 20 72 6f 6f 74 20 6f |-- Find |a root o|
|00000090| 66 20 61 20 66 75 6e 63 | 74 69 6f 6e 2e 0d 2d 2d |f a func|tion..--|
|000000a0| 20 54 68 65 20 75 73 65 | 72 20 6d 75 73 74 20 73 | The use|r must s|
|000000b0| 75 70 70 6c 79 20 61 20 | 64 65 66 69 6e 69 74 69 |upply a |definiti|
|000000c0| 6f 6e 20 66 28 78 29 20 | 61 6e 64 20 78 31 2c 78 |on f(x) |and x1,x|
|000000d0| 32 20 76 61 6c 75 65 73 | 20 74 68 61 74 20 62 72 |2 values| that br|
|000000e0| 61 63 6b 65 74 20 74 68 | 65 20 72 6f 6f 74 2e 20 |acket th|e root. |
|000000f0| 54 68 65 20 72 6f 6f 74 | 20 69 73 20 66 6f 75 6e |The root| is foun|
|00000100| 64 20 74 6f 20 77 69 74 | 68 69 6e 20 b1 74 6f 6c |d to wit|hin .tol|
|00000110| 20 28 64 65 66 61 75 6c | 74 20 73 65 74 74 69 6e | (defaul|t settin|
|00000120| 67 20 31 65 2d 37 29 2e | 0d 2d 2d 20 54 65 63 68 |g 1e-7).|.-- Tech|
|00000130| 6e 69 63 61 6c 6c 79 20 | 74 68 65 20 73 69 67 6e |nically |the sign|
|00000140| 20 6f 66 20 66 28 78 29 | 20 73 68 6f 75 6c 64 20 | of f(x)| should |
|00000150| 62 65 20 64 69 66 66 65 | 72 65 6e 74 20 61 74 20 |be diffe|rent at |
|00000160| 78 31 20 61 6e 64 20 61 | 74 20 78 32 20 28 74 68 |x1 and a|t x2 (th|
|00000170| 69 73 20 67 75 61 72 61 | 6e 74 65 65 73 20 74 68 |is guara|ntees th|
|00000180| 65 72 65 20 69 73 20 61 | 74 20 6c 65 61 73 74 20 |ere is a|t least |
|00000190| 6f 6e 65 20 72 6f 6f 74 | 20 62 65 74 77 65 65 6e |one root| between|
|000001a0| 20 78 31 20 61 6e 64 20 | 78 32 29 20 62 75 74 20 | x1 and |x2) but |
|000001b0| 74 68 69 73 20 72 6f 75 | 74 69 6e 65 20 77 69 6c |this rou|tine wil|
|000001c0| 6c 20 75 73 75 61 6c 6c | 79 20 63 6f 6e 76 65 72 |l usuall|y conver|
|000001d0| 67 65 20 61 73 20 6c 6f | 6e 67 20 61 73 20 74 68 |ge as lo|ng as th|
|000001e0| 65 72 65 20 69 73 20 61 | 20 72 6f 6f 74 20 73 6f |ere is a| root so|
|000001f0| 6d 65 77 68 65 72 65 20 | 6e 65 61 72 20 78 31 20 |mewhere |near x1 |
|00000200| 6f 72 20 78 32 2e 0d 0d | 2d 2d 20 65 78 61 6d 70 |or x2...|-- examp|
|00000210| 6c 65 0d 0d 66 28 78 29 | 20 3d 20 78 5e 33 20 2d |le..f(x)| = x^3 -|
|00000220| 20 32 2a 78 0d 0d 70 6c | 6f 74 20 66 28 58 29 0d | 2*x..pl|ot f(X).|
|00000230| 58 6d 69 6e 3d 2d 32 3b | 20 58 6d 61 78 3d 32 0d |Xmin=-2;| Xmax=2.|
|00000240| 0d 72 31 3a 3d 72 6f 6f | 74 28 2d 32 2c 2d 31 29 |.r1:=roo|t(-2,-1)|
|00000250| 2c 20 72 31 3a 2d 31 2e | 34 31 34 0d 72 32 3a 3d |, r1:-1.|414.r2:=|
|00000260| 72 6f 6f 74 28 2d 31 2c | 31 29 2c 20 20 72 32 3a |root(-1,|1), r2:|
|00000270| 30 2e 30 30 30 0d 72 33 | 3a 3d 72 6f 6f 74 28 31 |0.000.r3|:=root(1|
|00000280| 2c 32 29 2c 20 20 20 72 | 33 3a 31 2e 34 31 34 0d |,2), r|3:1.414.|
|00000290| 0d 70 6c 6f 74 20 7b 7b | 72 31 2c 72 32 2c 72 33 |.plot {{|r1,r2,r3|
|000002a0| 7d 2c 7b 30 2c 30 2c 30 | 7d 7d 0d 0d 2d 2d 2d 2d |},{0,0,0|}}..----|
|000002b0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000002c0| 0d 2d 2d 20 54 68 69 73 | 20 72 6f 75 74 69 6e 65 |.-- This| routine|
|000002d0| 20 75 73 65 73 20 74 68 | 65 20 22 66 61 6c 73 65 | uses th|e "false|
|000002e0| 20 70 6f 73 69 74 69 6f | 6e 22 20 61 6c 67 6f 72 | positio|n" algor|
|000002f0| 69 74 68 6d 2e 20 54 68 | 65 20 6e 65 78 74 20 67 |ithm. Th|e next g|
|00000300| 75 65 73 73 20 69 73 20 | 6f 62 74 61 69 6e 65 64 |uess is |obtained|
|00000310| 20 62 79 20 66 69 6e 64 | 69 6e 67 20 78 20 61 74 | by find|ing x at|
|00000320| 20 74 68 65 20 7a 65 72 | 6f 20 63 72 6f 73 73 69 | the zer|o crossi|
|00000330| 6e 67 20 6f 66 20 61 20 | 6c 69 6e 65 20 64 72 61 |ng of a |line dra|
|00000340| 77 6e 20 62 65 74 77 65 | 65 6e 20 74 68 65 20 70 |wn betwe|en the p|
|00000350| 72 65 76 69 6f 75 73 20 | 67 75 65 73 73 65 73 2e |revious |guesses.|
|00000360| 0d 0d 72 6f 6f 74 28 78 | 31 2c 78 32 29 20 3d 20 |..root(x|1,x2) = |
|00000370| 66 6c 6f 3a 3d 66 28 78 | 31 29 2c 0d 20 20 20 66 |flo:=f(x|1),. f|
|00000380| 68 69 3a 3d 66 28 78 32 | 29 2c 0d 20 20 20 28 28 |hi:=f(x2|),. ((|
|00000390| 78 6c 3a 3d 78 31 2c 78 | 68 3a 3d 78 32 29 20 77 |xl:=x1,x|h:=x2) w|
|000003a0| 68 65 6e 20 66 6c 6f 3c | 66 68 69 2c 20 20 2d 2d |hen flo<|fhi, --|
|000003b0| 20 6f 72 64 65 72 20 78 | 6c 2c 78 68 0d 20 20 20 | order x|l,xh. |
|000003c0| 20 28 78 6c 3a 3d 78 32 | 2c 78 68 3a 3d 78 31 2c | (xl:=x2|,xh:=x1,|
|000003d0| 73 77 61 70 3a 3d 66 6c | 6f 2c 66 6c 6f 3a 3d 66 |swap:=fl|o,flo:=f|
|000003e0| 68 69 2c 66 68 69 3a 3d | 73 77 61 70 29 29 2c 0d |hi,fhi:=|swap)),.|
|000003f0| 20 20 20 64 65 6c 74 61 | 3a 3d 74 6f 6c 2c 20 20 | delta|:=tol, |
|00000400| 2d 2d 20 73 6f 20 22 77 | 68 69 6c 65 22 20 77 69 |-- so "w|hile" wi|
|00000410| 6c 6c 20 64 6f 20 31 73 | 74 20 6c 6f 6f 70 0d 20 |ll do 1s|t loop. |
|00000420| 20 20 28 28 74 72 79 78 | 3a 3d 78 6c 2b 28 78 68 | ((tryx|:=xl+(xh|
|00000430| 2d 78 6c 29 2a 66 6c 6f | 2f 28 66 6c 6f 2d 66 68 |-xl)*flo|/(flo-fh|
|00000440| 69 29 20 77 68 65 6e 20 | 66 6c 6f ad 66 68 69 2c |i) when |flo.fhi,|
|00000450| 0d 20 20 20 20 20 74 72 | 79 78 3a 3d 78 6c 2b 74 |. tr|yx:=xl+t|
|00000460| 6f 6c 2a 32 29 2c 20 2d | 2d 20 61 76 6f 69 64 20 |ol*2), -|- avoid |
|00000470| 7a 65 72 6f 20 73 6c 6f | 70 65 0d 20 20 20 20 74 |zero slo|pe. t|
|00000480| 72 79 3a 3d 66 28 74 72 | 79 78 29 2c 0d 20 20 20 |ry:=f(tr|yx),. |
|00000490| 20 28 64 65 6c 74 61 3a | 3d 78 6c 2d 74 72 79 78 | (delta:|=xl-tryx|
|000004a0| 2c 0d 20 20 20 20 20 20 | 78 6c 3a 3d 74 72 79 78 |,. |xl:=tryx|
|000004b0| 2c 0d 20 20 20 20 20 20 | 66 6c 6f 3a 3d 74 72 79 |,. |flo:=try|
|000004c0| 29 20 77 68 65 6e 20 74 | 72 79 3c 30 2c 0d 20 20 |) when t|ry<0,. |
|000004d0| 20 20 28 64 65 6c 74 61 | 3a 3d 78 68 2d 74 72 79 | (delta|:=xh-try|
|000004e0| 78 2c 0d 20 20 20 20 20 | 20 78 68 3a 3d 74 72 79 |x,. | xh:=try|
|000004f0| 78 2c 0d 20 20 20 20 20 | 20 66 68 69 3a 3d 74 72 |x,. | fhi:=tr|
|00000500| 79 29 20 29 20 77 68 69 | 6c 65 20 61 62 73 28 64 |y) ) whi|le abs(d|
|00000510| 65 6c 74 61 29 b3 74 6f | 6c 2c 0d 20 20 20 74 72 |elta).to|l,. tr|
|00000520| 79 78 20 20 2d 2d 20 72 | 65 74 75 72 6e 20 6c 61 |yx -- r|eturn la|
|00000530| 73 74 20 67 75 65 73 73 | 0d 0d 74 6f 6c 3d 31 65 |st guess|..tol=1e|
|00000540| 2d 37 0d 0d 00 00 00 00 | 00 00 00 00 00 00 00 00 |-7......|........|
|00000550| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000560| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000570| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000580| 00 00 01 00 00 00 01 24 | 00 00 00 24 00 00 00 32 |.......$|...$...2|
|00000590| 61 64 61 66 61 67 61 6a | 61 6b 61 6c 61 6d 61 6e |adafagaj|akalaman|
|000005a0| 61 70 61 72 61 73 61 74 | 61 76 61 78 62 65 62 6c |aparasat|avaxbebl|
|000005b0| 0b 72 6f 6f 74 20 66 69 | 6e 64 65 72 02 00 00 00 |.root fi|nder....|
|000005c0| 54 45 58 54 4d 50 61 64 | 01 00 00 68 00 80 00 00 |TEXTMPad|...h....|
|000005d0| 00 00 54 45 58 54 4d 50 | 61 64 01 00 00 68 00 80 |..TEXTMP|ad...h..|
|000005e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000005f0| 00 00 aa 0c 17 67 00 00 | 04 c4 00 00 01 56 69 72 |.....g..|.....Vir|
|00000600| 69 73 69 74 69 76 6a 65 | 6b 65 6b 6c 6b 72 6c 65 |isitivje|keklkrle|
|00000610| 6d 65 6d 6b 6d 73 6d 78 | 6e 65 6e 67 6f 00 6f 62 |memkmsmx|nengo.ob|
|00000620| 6f 64 6f 66 6f 67 6f 6b | 6f 6c 6f 6d 6f 6e 6f 70 |odofogok|olomonop|
|00000630| 6f 72 6f 73 6f 74 6f 76 | 6f 78 70 65 70 6c 70 72 |orosotov|oxpeplpr|
|00000640| 71 65 72 65 73 65 73 66 | 73 68 73 6b 73 6c 73 6d |qeresesf|shskslsm|
|00000650| 73 6e 73 70 73 74 73 76 | 74 65 74 68 74 72 75 00 |snspstsv|tethtru.|
|00000660| 75 62 75 64 75 66 75 67 | 75 6b 75 6c 75 6d 75 6e |ubudufug|ukulumun|
|00000670| 75 70 75 72 75 73 75 74 | 75 76 75 78 76 65 77 00 |upurusut|uvuxvew.|
|00000680| 00 00 00 20 04 02 00 03 | 00 02 3f f9 8e fa 35 12 |... ....|..?...5.|
|00000690| 94 e9 c8 ae 01 43 01 2c | 00 03 00 28 00 bb 01 2e |.....C.,|...(....|
|000006a0| 01 42 00 27 00 00 01 00 | 00 00 01 24 00 00 00 24 |.B.'....|...$...$|
|000006b0| 00 00 00 32 00 6e 20 7c | 07 b8 00 00 00 1c 00 32 |...2.n ||.......2|
|000006c0| 00 00 50 52 65 66 00 00 | 00 0a 00 80 ff ff 00 00 |..PRef..|........|
|000006d0| 00 00 00 6e 1f d0 00 00 | 00 00 00 00 00 00 00 00 |...n....|........|
|000006e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+